package com.kili.picture.context;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 返回报文格式
 */
@Data
@ApiModel("接口返回")
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("状态")
    private Integer status;
    @ApiModelProperty("信息说明")
    private String message;
    @ApiModelProperty("时间戳")
    private Long timestamp;
    @ApiModelProperty("数据")
    private T data;


    public Result() {
        this.timestamp = System.currentTimeMillis();
    }

    public Result(T data) {
        this.timestamp = System.currentTimeMillis();
        this.status = ResultStatus.OK.getValue();
        this.message = ResultStatus.OK.getReasonPhrase();
        this.data = data;
    }

    public Result(Integer status, String msg) {
        this.timestamp = System.currentTimeMillis();
        this.status = status;
        this.message = msg;
    }

    public void setResultStatus(ResultStatus status) {
        this.status = status.getValue();
        this.message = status.getReasonPhrase();
    }

    public static <T> Result<T> of(T data) {
        return new Result<>(data);
    }

    public static <T> Result<T> of() {
        return new Result<>(null);
    }

    public static <T> Result<T> of(ResultStatus status) {
        return new Result<>(status.getValue(), status.getReasonPhrase());
    }

    public static <T> Result<T> of(Integer status, String msg) {
        return new Result<>(status, msg);
    }

}